<template>
  <view class="body">
    <view class="name titleBold">{{ info.name }}<span v-if="info.noRequire">(非必填)</span></view>
    <view v-if="info.tips" class="tips"> {{ info.tips }} </view>
    <view class="sickList">
      <view
        v-for="item in info.options"
        :key="item.id"
        :class="[info.rowBlock === true ? 'sickBox blocks' : 'sickBox']"
      >
        <view :class="[checkValue === item.id ? 'sickSpan cur' : 'sickSpan']" @click="choseList(info, item)">
          {{ item.name }}
          <span v-if="checkValue === item.id" class="curImg"><img :src="curIcon" /></span>
        </view>
        <view v-if="item.tips" class="kidTips">{{ item.tips }}</view>
      </view>
    </view>
  </view>
  <!-- 下一题上一题按钮 -->
  <!-- <nextProBtnCom @nextBtn="nextBtn" @proBtn="proBtn"></nextProBtnCom> -->
</template>

<script>
// import { ajaxSend } from './ajaxHealth.js';
import curIcon from '@/static/icon/cur.png';
export default {
  props: {
    // 是否展示搜索按钮
    info: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      checkValue: undefined,
      curIcon: curIcon,
      noChose: false
    };
  },
  computed: {
    active() {
      return this.$store.getters.active;
    },
    assessForm() {
      return this.$store.getters.assessForm;
    },
    uSex() {
      return this.$store.getters.userSex;
    }
  },
  methods: {
    validate() {
      if (!this.checkValue && this.checkValue !== 0 && !this.info.noRequire) {
        uni.showToast({ title: `请选择${this.info.name}`, icon: 'none' });
        return false;
      } else {
        return { [this.info.key]: this.checkValue };
      }
    },
    // async success() {
    //   let submitData = this.assessForm;
    //   submitData[this.info.key] = this.checkValue;
    //   // 获取健康指标指导意见 判断是出健康提示还是直接下一步 start
    //   const ajaxData = {
    //     [this.info.key]: this.checkValue
    //   };
    //   let healthData = await ajaxSend(ajaxData);
    //   let curActive = 0;
    //   if (this.uSex && this.uSex === '男' && this.active === 6) {
    //     curActive = this.active + 2;
    //   } else {
    //     curActive = this.active + 1;
    //   }
    //   const checkKeyIsInput = [
    //     {
    //       nameKey: 'hPylori',
    //       title: '幽门螺杆菌',
    //       healthGuidances: ['建议作为常规体检项目及早检查。']
    //     }
    //   ];
    //   if (this.checkValue === 30 && this.active === 23) {
    //     healthData = checkKeyIsInput;
    //   }

    //   if (healthData && healthData.length > 0) {
    //     // 如果有异常，则提示
    //     this.$store.commit('assessQuestion/SET_AJAXRESMESSAGE', healthData); // 存提示信息到vux，数组格式
    //     this.$store.commit('assessQuestion/SET_AJAXRES', true); // 开启提示
    //   } else {
    //     this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    //     this.$store.commit('assessQuestion/SET_AJAXRES', false);
    //   }
    //   // 获取健康指标指导意见 判断是出健康提示还是直接下一步 end
    //   this.$store.commit('assessQuestion/SET_ASSESSFORM', submitData);
    // },
    proBtn() {
      let curActive = 0;
      if (this.uSex && this.uSex === '男' && this.active === 8) {
        curActive = this.active - 2;
      } else {
        curActive = this.active - 1;
      }
      // curActive = this.active - 1;
      this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    },
    choseList(info, item) {
      this.checkValue = item.id;
      // let key = info.key;
      this.$emit('choseList', info.key, this.validate);
    }
  }
};
</script>
<style lang="scss" scoped>
.body {
  padding: 24rpx;
  margin-bottom: 30rpx;
}
.name {
  padding: 20rpx 0;
}
.tips {
  color: rgba(0, 0, 0, 0.55);
  font-size: 28rpx;
  margin-bottom: 20rpx;
  padding: 0 16rpx;
}
.sickList {
  .sickBox {
    display: inline-block;
    width: 50%;
    .sickSpan {
      display: inline-block;
      text-align: center;
      width: 80%;
      padding: 10rpx 18rpx;
      margin: 12rpx 16rpx;
      border: 2rpx solid rgba(178, 178, 178, 1);
      border-radius: 16rpx;
      font-size: 28rpx;
      position: relative;
      .curImg {
        position: absolute;
        width: 40rpx;
        height: 40rpx;
        right: 0;
        bottom: 0;
        border: none;
        img {
          width: 40rpx;
          height: 40rpx;
        }
      }
    }
    .cur {
      border: 2rpx solid rgba(242, 85, 89, 1);
      color: rgba(242, 85, 89, 1);
    }
    .kidTips {
      color: rgba(0, 0, 0, 0.55);
      font-size: 28rpx;
      margin-bottom: 30rpx;
      padding: 0 16rpx;
    }
  }
  .blocks {
    display: block;
    width: 100%;
    .sickSpan {
      width: 590rpx;
    }
  }
}

.clear {
  clear: both;
  overflow: hidden;
  zoom: 1;
  height: 0px;
}
.lineHeight86 {
  height: 86rpx;
  line-height: 86rpx;
}
.size28 {
  font-size: 28rpx;
}
.titleBold {
  font-weight: 500;
}
</style>
